package org.example.work.controller;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.example.work.pojo.Comment;
import org.example.work.pojo.Result;
import org.example.work.service.CommentService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/comment")
@Validated
public class CommentController {

    @Resource
    private CommentService commentService;

    @PostMapping("/add")
    public Result<String> showContent(@Valid @RequestBody Comment comment) {
        commentService.addComment(comment);
        return Result.success("评论成功");
    }

    @PostMapping("/reply")
    public Result<String> showReply(@RequestBody Comment comment) {

        commentService.replyComment(comment);
        return Result.success("回复成功");
    }

    @GetMapping("/list")
    public Result showCommentList(@RequestParam Long taskid) {
        System.out.println(taskid);
        List<Comment> comments = commentService.findCommentsByTaskId(taskid);
        if (comments != null && !comments.isEmpty()) {
            return Result.success(comments);
        } else {
            return Result.success("还没有人评论");
        }
    }
}